import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { updateFarmlandWeather } from 'utils/Api'
import { Modal } from 'antd'
import Forms from './Forms'
import { toast } from 'react-toastify'

class Modals extends Component {
  constructor(props) {
    super(props)
    this.state = {
      visible: props.visible
    }
  }
  handleCreate = () => {
    const info = this.formRef.getItemsValue()
    if (!info) {
      return
    }
    const fd = new FormData()
    fd.append('infoStr', JSON.stringify(info))
    updateFarmlandWeather(fd)
      .then(({msg}) => {
        if (data.msg === '200') {
          toast.success('保存成功')
        }
      })
  }
  render() {
    return (
      <Modal
        wrapClassName='modals'
        width={1000}
        title={'降水灌溉'}
        visible={this.props.visible}
        okText={'保存'}
        cancelText={''}
        onOk={this.handleCreate}
        onCancel={ () => this.props.closeModal()}
        destroyOnClose={true}
      >
        <Forms ref={form => this.formRef = form} {...this.props}/>
      </Modal>
    )
  }
}

Modals.propTypes = {
  visible: PropTypes.bool,
  closeModal: PropTypes.func,
}

export default Modals